package com.atguigu.spring.jdbc.service;

import com.atguigu.spring.aop.xml.Book;
import com.atguigu.spring.jdbc.dao.CityDao;
import com.atguigu.spring.jdbc.entity.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yanglin
 * @create 2023-12-12 17:20 星期二
 * description:
 */
@Service
public class CityService {
    
    
    @Autowired
    CityDao cityDao;
    
    //添加方法
    public void addCity(City city){
        ApplicationContext applicationContext = 
                new ClassPathXmlApplicationContext("./druid.xml");
//        CityDao cityDao = applicationContext.getBean("cityDao", CityDao.class);
        cityDao.addCity(city);
    }
    
    
    //修改方法
    public void update(City city){
        cityDao.updateCity(city);
    }
    
    //删除方法
    public void deleteBook(Integer id){
        cityDao.deleteCity(id);
    }
    
    //查询记录数
    public int findCount(){
        Integer num = cityDao.findCount();
        return num;
    }
    
    //查询一个城市
    public City findOne(Integer id){
        City city = cityDao.findOne(id);
        return city;
    }
    
    //查询城市  返回一个集合
    public List<City> findList(){
        List<City> list = cityDao.findList();
        return list;
    }

    
    //批量添加
    public void batchAdd(List<Object[]> batchArgs){
        cityDao.batchAdd(batchArgs);
    }
    
    //批量修改
    public void batchUpdate(List<Object[]> batchArgs){
        cityDao.batchUpdate(batchArgs);
    }

    //批量删除
    public void batchDelete(List<Object[]> batchArgs){
        cityDao.batchDelete(batchArgs);
    }
    
}
